package com.yuzhi.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @ClassName: SoilPhEnum
 * @Author: Mario
 * @Date: 2024-08-18 15:04
 * @Description: 土壤电导率枚举值
 * @ProjectName: drainageapp-area
 * @PackageName: com.yuzhi.common.enums
 */
@Getter
@AllArgsConstructor
public enum SoilEcEnum {

    EXCELLENT("优良土壤", Double.NEGATIVE_INFINITY, 50, 100),
    MODERATE("中等土壤", 50, 200, 80),
    SLIGHTLY_SALINE("轻度盐碱土壤", 200, 400, 60),
    MODERATELY_SALINE("中度盐碱土壤", 400, 800, 40),
    HIGHLY_SALINE("重度盐碱土壤", 800, Double.POSITIVE_INFINITY, 20);

    private final String desc;

    private final double minValue;

    private final double maxValue;

    private final double calculationValue;

    public static double getCalculationValue(double conductivity) {
        return Arrays.stream(values())
                .filter(level -> conductivity >= level.getMinValue() && conductivity < level.getMaxValue())
                .findFirst()
                .map(SoilEcEnum::getCalculationValue)
                .orElseThrow(() -> new IllegalArgumentException("Invalid soil ec value"));
    }
}
